package cn.com.generaldata.os.service.indicator_evaluation.composition_analysis;

import org.apache.commons.lang3.Validate;

import cn.com.generaldata.jsme_indicator_system.entity.IndicatorEvaluation;
import cn.com.generaldata.os.service.indicator_constant.ProvinceIndicatorConstant;
import cn.com.generaldata.os.service.indicator_evaluation.IndicatorEvaluationCalculateService;
import cn.com.generaldata.os.util.BeanMapper;
import cn.com.generaldata.os.vo.IndicatorAccountVO;

/**
 * 县级海洋生产总值占省级海洋生产总值比重评估指标计算类.
 */
public class GOPOfCountyCalculateService extends IndicatorEvaluationCalculateService {

	private String BaseIndicatorName = ProvinceIndicatorConstant.GOP_INDICATOR_NAME;

	@Override
	protected Double calculate(IndicatorEvaluation indicator, IndicatorAccountVO indicatorAccountVO) {

		Double currentBase = getBaseIndicatorVal(indicatorAccountVO, indicatorAccountVO.getYear());
		Validate.isTrue(currentBase != null);

		Double currentProvince = geInternalIndicatorVal(indicatorAccountVO, indicatorAccountVO.getYear());
		Validate.isTrue(currentProvince != null);

		return (currentBase / currentProvince) * 100;
	}

	private Double geInternalIndicatorVal(IndicatorAccountVO indicatorAccountVO, int year) {
		IndicatorAccountVO countryIndicator = BeanMapper.map(indicatorAccountVO, IndicatorAccountVO.class);
		countryIndicator.setAreaId(ProvinceIndicatorConstant.PROVICE_AREA_ID);
		return getInputOrAccountingIndicatorValue(countryIndicator, year, BaseIndicatorName);
	}

	private Double getBaseIndicatorVal(IndicatorAccountVO indicatorAccountVO, int year) {
		return getInputOrAccountingIndicatorValue(indicatorAccountVO, year, BaseIndicatorName);
	}

}
